package com.mj.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import com.androidquery.AQuery;
import com.mj.R;
import com.mj.activity.publish.PublishActivity;
import com.mj.bean.Album;
import com.mj.util.DensityUtil;

public class PicAdapter extends ArrayAdapter<Album> {
	// 真实宽度
	private double realWidth;

	public PicAdapter(Context context, ArrayList<Album> arrayList) {
		super(context, 0, arrayList);
		realWidth = (DensityUtil.getDisplay(context).widthPixels - DensityUtil.dip2px(context, 30)) / 2;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.item_pic, null);
		}
		final Album album = getItem(position);
		// 真实宽高
		double ratio = realWidth / album.getWidth();
		int realHeight = (int) (album.getHeight() * ratio);
		AQuery aq = new AQuery(convertView);
		aq.id(R.id.imageView1).width((int) realWidth, false).height(realHeight, false);
		aq.id(R.id.rl_infos).visible();
		aq.id(R.id.imageView1).image(album.getImg());
		return convertView;
	}

	/***
	 * 个人大图页
	 */
	public void bigpic(Album album) {
		Intent intent = new Intent(getContext(), PublishActivity.class);
		intent.putExtra("album", "album");
		getContext().startActivity(intent);
	}
}
